package com.wangsd.web.coupon.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wangsd.web.coupon.entity.FileManagement;
import com.wangsd.web.coupon.mapper.FileManagementMapper;
import com.wangsd.web.coupon.service.FileManagementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 服务实现类
 * </p>
 *
 * @author generator
 * @since 2019-09-19
 */
@Service
public class FileManagementServiceImpl extends ServiceImpl<FileManagementMapper, FileManagement> implements FileManagementService {

    @Resource
    FileManagementMapper fileManagementMapper;

    @Override
    public int deleteByMasterIdAndType(FileManagement fileManagement) {
        /*删除管理数据*/
        Long masterId = fileManagement.getMasterId();
        Integer type = fileManagement.getType();
        QueryWrapper<FileManagement> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("master_id", masterId);
        if (type != null) {
            queryWrapper.eq("type", fileManagement.getType());
        }
        return fileManagementMapper.delete(queryWrapper);
    }

    @Override
    public List<FileManagement> selectByMasterIdOrType(FileManagement fileManagement) {
        Long masterId = fileManagement.getMasterId();
        Integer type = fileManagement.getType();
        QueryWrapper<FileManagement> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("master_id", masterId);
        if (type != null) {
            queryWrapper.eq("type", type);
        }
        return fileManagementMapper.selectList(queryWrapper);
    }

    @Override
    public List<FileManagement> selectByMasterIdAndCompanyId(Long masterId, int type) {
        QueryWrapper<FileManagement> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("master_id",masterId);
        queryWrapper.eq("type",type);
        List<FileManagement> fileManagements = fileManagementMapper.selectList(queryWrapper);
        return fileManagements;
    }
}
